package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduCourseClassDTO;
import com.zenith.edu.po.vo.EduCourseClassVO;
import com.zenith.edu.service.EduCourseClassService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/course-class")
@Tag(name = "课程班级关系管理", description = "课程班级关系管理接口")
public class EduCourseClassController {
    
    @Autowired
    private EduCourseClassService eduCourseClassService;
    
    @SecurePostMapping(value = "/createCourseClass", roles = "ROLE_ADMIN", permission = "course-class:create")
    @Operation(summary = "创建课程班级关系")
    public Result<EduCourseClassVO> createCourseClass(@RequestBody EduCourseClassDTO dto) {
        EduCourseClassVO courseClassVO = eduCourseClassService.createCourseClass(dto);
        return Result.success(courseClassVO);
    }
    
    @SecurePostMapping(value = "/getCourseClassById/{id}", roles = "ROLE_ADMIN", permission = "course-class:read")
    @Operation(summary = "根据ID获取课程班级关系详情")
    public Result<EduCourseClassVO> getCourseClassById(@PathVariable Long id) {
        EduCourseClassVO courseClassVO = eduCourseClassService.getCourseClassById(id);
        if (courseClassVO == null) {
            return Result.fail("课程班级关系不存在");
        }
        return Result.success(courseClassVO);
    }
    
    @SecurePostMapping(value = "/updateCourseClass", roles = "ROLE_ADMIN", permission = "course-class:update")
    @Operation(summary = "更新课程班级关系信息")
    public Result<EduCourseClassVO> updateCourseClass(@RequestBody EduCourseClassDTO dto) {
        EduCourseClassVO courseClassVO = eduCourseClassService.updateCourseClass(dto);
        return Result.success(courseClassVO);
    }
    
    @SecurePostMapping(value = "/deleteCourseClass/{id}", roles = "ROLE_ADMIN", permission = "course-class:delete")
    @Operation(summary = "删除指定课程班级关系")
    public Result<Void> deleteCourseClass(@PathVariable Long id) {
        boolean result = eduCourseClassService.deleteCourseClass(id);
        if (!result) {
            return Result.fail("课程班级关系删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getCourseClassList", roles = "ROLE_ADMIN", permission = "course-class:read")
    @Operation(summary = "获取课程班级关系列表")
    public Result<List<EduCourseClassVO>> getCourseClassList() {
        List<EduCourseClassVO> courseClassList = eduCourseClassService.getCourseClassList();
        return Result.success(courseClassList);
    }
}